package com.gree.changying.activity.searchactivity;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gree.changying.R;
import com.gree.changying.activity.base.BasePageActivity;
import com.gree.changying.activity.searchactivity.adapter.SearchAdapter;
import com.gree.changying.activity.searchactivity.bean.Search;
import com.gree.changying.server.bean.IntentKV;
import com.gree.changying.widget.refreshLayout.MaterialSmoothRefreshLayout;
import com.gree.changying.widget.refreshLayout.lib.SmoothRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SearchResultActivity extends BasePageActivity  implements   SmoothRefreshLayout.OnRefreshListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_result);
        ButterKnife.bind(this);
        String value = IntentKV.get(this,"value");
        if(value.length()>5){
            value = value.substring(0,5)+"..";
        }
        setTitle("搜索\""+value+"\"的结果");
        initRv();
    }

    @Override
    public boolean setStatusBar() {
        setStatusBar(R.color.white,true);
        return false;
    }

    @Override
    public boolean onFinish() {
        return true;
    }

    @Override
    public void onRightBtnClick(View view) {

    }



    @Bind(R.id.rv)
    RecyclerView rv;
    private SearchAdapter rvAdapter;
    private void initRv(){
        refreshLayout.setDisableLoadMore(false);
        refreshLayout.setEnableAutoRefresh(false);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setDisableLoadMoreWhenContentNotFull(true);
        refreshLayout.setEnableAutoLoadMore(true);
        refreshLayout.autoRefresh(true);
        refreshLayout.autoLoadMore(false);
        rv.setLayoutManager(new LinearLayoutManager(mContext));
        rvAdapter = new SearchAdapter(R.layout.item_search_result,getZxzx());
        rv.setAdapter(rvAdapter);
    }

    private Object[][] zxzxList = {
            {R.drawable.touxiang,"测试搜索","42%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","43%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","44%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","45%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","46%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","47%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","48%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","49%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","49%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","45%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","43%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","44%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","45%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","42%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","46%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","47%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","43%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","44%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","43%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","44%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","43%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","45%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","42%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","42%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
            {R.drawable.touxiang,"测试搜索","42%","35积分","土超","2020/03/23","1.0","日耳曼","日耳曼","摩洛哥","1-2"},
    };
    private List<Search> getZxzx(){
        List<Search> rmsses = new ArrayList<>();
        for(Object[] o:zxzxList){
            Search rmss = new Search();
            rmss.setImg((int)o[0]);
            rmss.setTitle((String)o[1]);
            rmss.setSl((String)o[2]);
            rmss.setJf((String)o[3]);
            rmss.setTag((String)o[4]);
            rmss.setDate((String)o[5]);
            rmss.setRq((String)o[6]);
            rmss.setName1((String)o[7]);
            rmss.setName2((String)o[8]);
            rmss.setName3((String)o[9]);
            rmss.setBf((String)o[10]);
            rmsses.add(rmss);
        }
        return rmsses;
    }

    @Bind(R.id.refreshLayout)
    MaterialSmoothRefreshLayout refreshLayout;
    @Override
    public void onRefreshing() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshLayout.refreshComplete();
            }
        },1000);
    }

    @Override
    public void onLoadingMore() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshLayout.refreshComplete();
            }
        },1000);
    }
}